import selenium
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

options = ChromeOptions()
options.add_argument("--headless")
driver = Chrome(executable_path='/Users/sonto/Downloads/webdriver/79/chromedriver',
                options=options)
driver.get('https://movie.douban.com')
import time
time.sleep(10)
for p in driver.find_elements_by_class_name("item"):
    print(p)

# 设置COOKIE
# driver.add_cookie({'name' : 'foo', 'value' : 'bar'})

# driver.switch_to_alert()
# alert = driver.switch_to.alert()
# print(alert.text)

# driver.
import time
time.sleep(5)
# try:
    # # 构造WAIT对象
    # wait = WebDriverWait(driver, 10)
    #
    # # 构造等待条件
    # condition = expected_conditions.presence_of_element_located((By.CLASS_NAME, 'item'))
    #
    # # condition = expected_conditions.url_contains('douban.com')
    # # 等待直到指定的条件发生
    # wait.until(condition)
    #
    # # 提取数据
    # for i in driver.find_elements_by_class_name("item"):
    #     print(i)

driver.close()
# finally:
#     driver.quit()

# class PrintClass:
#     def __call__(self, string):
#         print(string)
#
# p = PrintClass()
# p("hello world!!!!!")